@page "/ClusterRole"
@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using k8s.Models
@using Mapster
@inherits BlazorApp.Pages.Common.TableBase<V1ClusterRole>
@if (TableData.PagedItems != null)
{
    <HTable Class="wideTable">
        <HTr>
            <HTd >
                <SearchToolBar Title=@L["ClusterRole"] Count="@TableData.Total" OnItemDeletedCallback="@(async () => await InvokeAsync(StateHasChanged))"
                               OnSelectedItemCloseClicked="@TableData.RemoveSelection"
                               OnRemoveAllClicked="@TableData.RemoveAllSelection"
                               TableData="@TableData"
                               OnSearch="OnSearchHandler" TItem="V1ClusterRole"
                               OnNsSelected="OnNsSelectedHandler"
                               HideNsSelector="true">
                </SearchToolBar>
            </HTd>
        </HTr>
        <HTr>
            <HTd >
                <Table TItem="V1ClusterRole"
                       DataSource="@TableData.PagedItems"
                       Size=@TableSize.Small Bordered="true"
                       Total="TableData.Total"
                       @bind-PageIndex="TableData.PageIndex"
                       @bind-PageSize="TableData.PageSize"
                       @bind-SelectedRows="TableData.SelectedRows"
                       Loading="TableData.Loading"
                       OnChange="OnPageChangeHandler">
                    <Selection Key="@(context.Name())"/>
                    <AntDesign.Column Field="@context.Name()" Title=@L["Name"]>
                        <Button OnClick="@(() => OnItemNameClick(context))" Type="@ButtonType.Link">@context.Name()</Button>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["User"] TData="string">
                        @foreach (var subject in ClusterRoleService.ListManagedSubjectByClusterRole(context))
                        {
                            <RefView Ref="@(subject.Adapt<V1ObjectReference>())" FullView="true"></RefView>
                        }
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Age"] TData="string" Width="100px">
                        <AgeView Age="@context.CreationTimestamp()"></AgeView>
                    </AntDesign.Column>
                    <ActionColumn Title=@L["Action"] Width="100px">
                        <ClusterRoleAction Item="@context"></ClusterRoleAction>
                    </ActionColumn>
                </Table>

            </HTd>
        </HTr>
    </HTable>

    <ResourceWatcher OnResourceChanged="OnResourceChanged" T="V1ClusterRole"></ResourceWatcher>
}
